package com.dsbj.mp.icardservice.controller.attendance;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsbj.common.msg.ResponseMessage;
import com.dsbj.mp.icardservice.controller.BaseController;
import com.dsbj.mp.icardservice.model.MpUser;
import com.dsbj.mp.icardservice.service.attendance.DayReportService;
import com.dsbj.mp.icardservice.utils.strprocess.ObjectParse;
import com.dsbj.mp.icardservice.utils.strprocess.StrUtil;
import com.dsbj.mp.icardservice.webserviceclient.dsbjpmc.AllowUser;
import com.dsbj.mp.icardservice.webserviceclient.dsbjpmc.AllowUserResponseMessage;
import com.dsbj.mp.icardservice.webserviceclient.dsbjpmc.JWSService;
import com.dsbj.mp.icardservice.webserviceclient.dsbjpmc.WxUser;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author cjw 2019-12-30
 */
@RestController
@RequestMapping("/attendance")
public class DayReportController extends BaseController {

	@Resource
	private JWSService jwsService;

	@Resource
	private DayReportService dayReportService;




	/**
	 * 根据条件,分页获取该用户自己的日考勤信息。
	 * 传入参数：startTime,endTime,pageNum,pageSize,conditions。
	 * 其中, conditions为条件集合字符串,条件之间以","分隔。
	 * @param
	 * @return
	 * @author cjw 2019-12-30
	 */
	@RequestMapping("/getDayReport")
	public ResponseMessage getDayReport(HttpServletRequest request, String fanganids, String startTime, String endTime,
										String sortName, String sortOrder, Integer pageNum, Integer pageSize, String conditions) {

		//获取wxUser信息
		MpUser wxUser=(MpUser) request.getAttribute("wxUser");

		//解析传来的参数
		try{
			startTime=ObjectParse.parse_toStr_elseException(startTime);
			endTime=ObjectParse.parse_toStr_elseException(endTime);
			pageNum=ObjectParse.parse_toInt(pageNum,1);
			pageSize=ObjectParse.parse_toInt(pageSize,10);
			conditions=ObjectParse.parse_toStr(conditions);

		}catch (Exception e){
			return ResponseMessage.error("传入参数有误!"+e.toString());
		}

		/**
		 * 根据条件,分页获取该用户自己的日考勤信息。
		 */
		//将传入参数存入map中。
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("pageNum",pageNum);
		map.put("pageSize",pageSize);
		map.put("sortName", sortName);
		map.put("sortOrder", sortOrder);

		if (StringUtils.isNotBlank(fanganids)) {
			map.put("fananEmployeeno", fanganids);
		}

		map.put("companyno", wxUser.getCompanyno());
		map.put("employeeno", wxUser.getEmployeeNo());
		map.put("minTime", startTime);
		map.put("maxTime", endTime);
		map.put("exception",StringUtils.split(conditions,","));
		Page page = dayReportService.queryPage(map);

		return ResponseMessage.ok(page);
	}


}
